package cn.dengta.webapp.user.model;

import java.util.Arrays;
import javax.annotation.Nullable;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.context.model.LabelI18nProxy;
import cn.dengta.context.model.UserEnumI18nKey;
import lombok.Getter;

/**
 * 用户状态枚举
 */
@Getter
public enum UserStatus implements LabelI18nProxy<UserStatus, Integer> {
	/** 已注销 */
	INVALID(-99, UserEnumI18nKey.USER_STATUS_INVALID, true),
	/** 注销中 */
	INVALIDING(-2, UserEnumI18nKey.USER_STATUS_INVALIDING, false),
	/** 暂停停用 */
	PAUSE(-1, UserEnumI18nKey.USER_STATUS_PAUSE, false),
	/** 待核实 */
	WAIT_VERIFY(0, UserEnumI18nKey.USER_STATUS_WAIT_VERIFY, false),
	/** 启用 */
	VALID(1, UserEnumI18nKey.USER_STATUS_VALID, true),
	/** 平台拉黑  拉黑用户 平台限制用户功能操作*/
	BLACK(9, UserEnumI18nKey.USER_STATUS_PLATFORM_BLOCK, true),
	//
	;

	public final Integer value;
	public final boolean show;
	public final ValueProxy<UserStatus, Integer> proxy;

	UserStatus(Integer value, String label, boolean show) {
		this.value = value;
		this.show = show;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	public static boolean canLogin(@Nullable Integer status) {
		return status != null && status >= UserStatus.WAIT_VERIFY.value;
	}

	public static boolean isSysBloack(@Nullable Integer status) {
		return UserStatus.BLACK.eq(status);
	}

	public static UserStatus[] CACHE = Arrays.stream(values()).filter(UserStatus::isShow).toArray(UserStatus[]::new);

	public static UserStatus[] getValues() {
		return ValueProxy.getCachedArray(UserStatus.class, UserStatus::values);
	}

	public static UserStatus of(Integer value) {
		return VALID.getValueOf(value);
	}

}
